package game;

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.Panel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;

public class SaveDialog extends JDialog implements ActionListener{
	private String saveString;
	private JTextArea saveInput;
	private JButton submit;
	private JButton cansel;

	/**
	 *
	 */
	private static final long serialVersionUID = 8456667368950348858L;

	public SaveDialog(Frame owner) {
		super(owner);

		// 各種コンポーネントの作成
		saveInput = new JTextArea();
		submit = new JButton("OK");
		submit.addActionListener(this);
		cansel = new JButton("Cansel");
		cansel.addActionListener(this);

		// コンポーネントをダイアログに配置
		setLayout(new BorderLayout());
		add(new JScrollPane(saveInput));
		Panel southPanel = new Panel();
		add(southPanel, BorderLayout.SOUTH);
		southPanel.setLayout(new FlowLayout());
		southPanel.add(submit);
		southPanel.add(cansel);
		saveInput.setLineWrap(true);

		// ダイアログの装飾
		setTitle("復活の呪文");
		setSize(240, 160);
		setModal(true);
	}

	public void setSaveString(String saveString){
		this.saveString = saveString;
		saveInput.setText(saveString);
	}

	public String getSaveString(){
		return saveString;
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		System.out.println(e.getSource());
		if(e.getSource() == submit){
			System.out.println("saved");
			saveString = saveInput.getText();
		}
		setVisible(false);
	}
}
